package com.goods.business.converter;

import com.goods.business.service.SupplierService;
import com.goods.common.model.business.Supplier;
import com.goods.common.response.ResponseBean;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Api(value = "物资来源")
@RestController
@RequestMapping("/business/supplier")
public class SupplierController {

   /* Request URL: http://www.localhost:8989/business/supplier/findSupplierList?pageNum=1&pageSize=10&name=
   http://www.localhost:8989/business/supplier/findSupplierList?pageNum=1&pageSize=10&name（名字）=3123&address（地址）=123&contact(联系人)=213
    Request Method: GET*/

   @Autowired
   private SupplierService supplierService;
    //查询所有
   @GetMapping("findSupplierList")
   public ResponseBean findSupplierList(Integer pageNum,Integer pageSize,String name,String address,String contact){
       List<Supplier> productCategoryTreeNodeVOList = supplierService.findSupplierList(pageNum,pageSize,name,address,contact);
       Map<Object, Object> map = new HashMap<>();
       map.put("rows",productCategoryTreeNodeVOList);
       map.put("totle",productCategoryTreeNodeVOList.size());
       return ResponseBean.success(map);
   }

   //添加物资来源ttp://www.localhost:8989/business/supplier/add
    //Request Method: POST
    @PostMapping("/add")
    public ResponseBean add(@RequestBody Supplier supplier){
        Boolean add = supplierService.add(supplier);
        if (add){
            return ResponseBean.success();
        }else{
            return ResponseBean.error("添加失败");
        }
    }

    //修改回显http://www.localhost:8989/business/supplier/edit/23
    //Request Method: GET
    @GetMapping("edit/{id}")
    public ResponseBean edit(int id){
        Supplier edit = supplierService.edit(id);
        return ResponseBean.success(edit);
    }
    //修改 "business/supplier/update/" + this.editRuleForm.id,
    @PutMapping("/update/{id}")
    public ResponseBean update(@RequestBody Supplier supplier){
        supplierService.update(supplier);
       return ResponseBean.success();
    }
    //删除delete("business/supplier/delete/" + id);
    @DeleteMapping("/delete/{id}")
    public ResponseBean delete(@PathVariable int id){
        supplierService.delete(id);
       return ResponseBean.success();
    }
//    Request URL: http://www.localhost:8989/business/supplier/findAll
//Request Method: GET
    @GetMapping("findAll")
    public ResponseBean findAll(){
       List<Supplier> supplierList =  supplierService.findAll();
       return ResponseBean.success(supplierList);
    }






}
